package cn.itcast.nems.enrol.converter;

import cn.itcast.nems.enrol.dao.dataobject.ActivityCourseDO;
import cn.itcast.nems.enrol.dto.ActivityCourseDTO;
import cn.itcast.nems.enrol.dto.SchoolSubjectDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * author liyong
 * create: 2024-04-16 16:20:43
 **/
public class ActivityCourseConverter {

    public static ActivityCourseDTO doToDTO(ActivityCourseDO courseDO) {
        ActivityCourseDTO dto = new ActivityCourseDTO();
        BeanUtils.copyProperties(courseDO, dto);
        final String[] ids = courseDO.getDiscountIds().split(",");
        final List<Integer> discountIds = new ArrayList<>();
        for (String id : ids) {
            if (StringUtils.hasText(id)) {
                discountIds.add(Integer.parseInt(id.trim()));
            }
        }
        dto.setDiscountIdList(discountIds);
        return dto;
    }

    public static SchoolSubjectDTO dtoToSchoolSubject(ActivityCourseDTO courseDTO) {
        SchoolSubjectDTO dto = new SchoolSubjectDTO();
        BeanUtils.copyProperties(courseDTO, dto);
        return dto;
    }
}
